package per.qiao.simplerest.restresolver;

import per.qiao.simplerest.restargument.RestParameter;
import per.qiao.simplerest.restenum.RestMethod;

import java.lang.reflect.Type;

/**
 * Company: 上海数惠系统技术有限公司
 * Department: 数据中心
 * Date: 2020-05-29 17:05
 *
 * @Author: qyp
 * Email: qiaoyp@dist.com.cn
 * Desc:
 */
public class RestInvokerMethod {

    /**
     * protocol + ip + port
     */
    private String base;

    /**
     * 请求uri
     */
    private String uri;

    /**
     * 请求方法
     */
    private RestMethod restMethod;

    /**
     * 方法参数
     */
    private RestParameter[] restParameter;

    /**
     * 返回值类型
     */
    @Deprecated
    private Class<?> returnType;

    /**
     * 返回值的泛型类型
     */
    private Type genericReturnType;


    public String getBase() {
        return base;
    }

    public void setBase(String base) {
        this.base = base;
    }

    public String getUri() {
        return uri;
    }

    private void setUri(String uri) {
        this.uri = uri;
    }

    public RestMethod getRestMethod() {
        return restMethod;
    }

    private void setRestMethod(RestMethod restMethod) {
        this.restMethod = restMethod;
    }

    public RestParameter[] getRestParameter() {
        return restParameter;
    }

    private void setRestParameter(RestParameter[] restParameter) {
        this.restParameter = restParameter;
    }

    public Class getReturnType() {
        return returnType;
    }

    private void setReturnType(Class returnType) {
        this.returnType = returnType;
    }

    public Type getGenericReturnType() {
        return genericReturnType;
    }

    public void setGenericReturnType(Type genericReturnType) {
        this.genericReturnType = genericReturnType;
    }

    public static MethodBuild createBuild() {
        return new MethodBuild();
    }


    public static class MethodBuild {
        private String base;
        private String uri;
        private RestMethod restMethod;
        private RestParameter[] restParameter;
        private Class<?> returnType;
        private Type genericReturnType;
        private MethodBuild() {
        }

        public MethodBuild base(String base) {
            this.base = base;
            return this;
        }

        public MethodBuild uri(String uri) {
            this.uri = uri;
            return this;
        }
        public MethodBuild restMethod(RestMethod restMethod) {
            this.restMethod = restMethod;
            return this;
        }
        public MethodBuild restParameter(RestParameter[] restParameter) {
            this.restParameter = restParameter;
            return this;
        }
        public MethodBuild genericReturnType(Type genericReturnType) {
            this.genericReturnType = genericReturnType;
            return this;
        }
        public MethodBuild returnType(Class returnType) {
            this.returnType = returnType;
            return this;
        }
        public RestInvokerMethod build() {
            RestInvokerMethod restInvokerMethod = new RestInvokerMethod();
            restInvokerMethod.setBase(this.base);
            restInvokerMethod.setUri(this.uri);
            restInvokerMethod.setRestMethod(this.restMethod);
            restInvokerMethod.setRestParameter(this.restParameter);
            restInvokerMethod.setReturnType(this.returnType);
            restInvokerMethod.setGenericReturnType(this.genericReturnType);
            return restInvokerMethod;
        }
    }
}
